package com.holystone.splunk.app.service;

import com.github.pagehelper.PageInfo;
import com.holystone.splunk.app.model.AlertVO;
import com.holystone.splunk.app.model.EventVO;
import org.codehaus.jackson.JsonNode;

import javax.mail.MessagingException;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;
import java.util.Set;

/**
 * Copyright (c) 2017, HOLYSTONE Technologies, Inc.
 * All right reserved.
 *
 * @author huyan
 * @date 2017/12/4
 * @desc:
 */
public interface IIndexEventService extends ISplunkIndexService {

    /**
     * 保存事件-告警关联关系
     * @param event
     * @param modelList
     */
    void saveEventAndAlerts(EventVO event, Set<AlertVO> modelList);

    /**
     * 插入一条事件记录
     * @param event
     */
    void insertEvent2Index(EventVO event) throws IOException;

    /**
     * 获取多个事件，根据事件ids
     *
     * @param eventIds
     * @return
     */
    List<EventVO> getEventByEventIds(String eventIds) throws IOException;

    /**
     * 获取已经存在的事件名称
     * @return
     */
    List<String> getExistsEventSorts() throws IOException;

    /**
     * 获取事件分页
     * @param pageNo
     * @param pageSize
     * @param conditions
     * @return
     */
    PageInfo<EventVO> getEventPageInfo(String pageNo, String pageSize, EventVO conditions) throws Exception;

    /**
     * 筛选出符合条件的事件信息
     * @param pageNo
     * @param pageSize
     * @param conditions
     * @return
     */
    List<EventVO> getEventsByConditions(Integer pageNo, Integer pageSize, EventVO conditions) throws Exception;

    /**
     * 筛选出符合条件的事件总数量
     * @param conditions
     * @return
     */
    Integer getEventsTotalCountByConditions(EventVO conditions) throws Exception;

    /**
     * 同源处理
     * @param alertSid
     * @param alertName
     * @param result
     * @return
     */
    String dealSameSource(String alertSid, String alertName, JsonNode result);

    /**
     * 保存修改后的事件信息
     * @param event
     */
    void updateEvent(EventVO event) throws IOException, MessagingException, ParseException;

    /**
     * 通过事件id获取告警分页
     * @param pageNo
     * @param pageSize
     * @param eventId
     * @return
     */
    PageInfo<AlertVO> getAlertsInfoByEventId(String pageNo, String pageSize, Long eventId) throws IOException;

    /**
     * 关闭事件
     * @param eventId
     * @param email
     */
    void closeEvent(Long eventId, String email) throws IOException, MessagingException;
}
